#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>
#include<fcntl.h>
#include<string.h>
#include<dirent.h>

void rmdir_all(char const path[200])
{
	struct stat buf;
	struct dirent *envdir;
	DIR *dirp;
	char file_name[200];

	stat(path, &buf);
	if(S_ISDIR(buf.st_mode))
	{
		dirp = opendir(path);
		while(envdir = readdir(dirp))
		{
			memset(file_name, 0, 200);
			strcat(file_name, path);
			strcat(file_name, "/");
			strcat(file_name, envdir -> d_name);
			stat(file_name, &buf);
			if(strcmp(envdir -> d_name, ".") == 0 || strcmp(envdir -> d_name, "..") == 0)
			{
				continue;
			}
			if(S_ISDIR(buf.st_mode))
				rmdir_all(file_name);
			else
				remove(file_name);
		}
		closedir(dirp);
		dirp = opendir(path);
		while(envdir = readdir(dirp))
		{
			memset(file_name, 0, 200);
			strcat(file_name, path);
			strcat(file_name, "/");
			strcat(file_name, envdir -> d_name);
			stat(file_name, &buf);
			rmdir(file_name);
		}
		closedir(dirp);

	}
	else
	{
		printf("error dir\n");
	}
}

int main(int argc, char const *argv[])
{
	if(argc != 2)
	{
		printf("error parameter\n");
	}
	rmdir_all(argv[1]);
	rmdir(argv[1]);
	return 0;
}